package com.lanou.service.impl;

import com.lanou.bean.User;
import com.lanou.mapper.UserMapper;
import com.lanou.service.UserService;
import com.lanou.utils.AjaxResult;
import com.lanou.utils.StrUtils;
import com.lanou.utils.TimeUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by dllo on 18/3/14.
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    /**
     *
     * @param phone 用户注册手机号
     * @param nickname 昵称
     * @param password 用户密码
     * @return 用户注册成功与否的信息
     * 开发人:赵帅
     */
    @Override
    public AjaxResult registUser(String phone, String nickname, String password) {
        String state= "注册失败";
        AjaxResult ajaxResult = new AjaxResult();
        if (!StrUtils.isNull(phone) && !StrUtils.isNull(nickname) && !StrUtils.isNull(password)) {
            if (StrUtils.isPhoneNumberRight(phone)) {
                if (userMapper.userLogin(phone) == null) {
                    userMapper.registUser(phone, nickname, password);
                    state= "注册成功";
                    ajaxResult.setCode("200");
                    ajaxResult.setMsg("注册成功");
                    ajaxResult.setData(state);
                } else {
                    state = "用户已存在";
                    ajaxResult.setCode("500");
                    ajaxResult.setMsg("注册失败");
                    ajaxResult.setData(state);
                }
            }
        }
        return ajaxResult;
    }

}
